import { report, QCcode } from "./request.js";
// console.log(ajax_tool);
let red = document.querySelector('.record')
let box = document.querySelector(".box")
let conname = document.querySelector('.conname')

let bigtitle = document.querySelector('.big_title')

// console.log(bg);
async function record() {
    // let url = 'http://newshopapi.0melon0.cn/api/f_user/report'
    let data = {
        // token: sessionStorage.getItem("token"),
        phone: sessionStorage.getItem("phone"),
        name: sessionStorage.getItem("name")
    }
    // render(res, result);
    let res = await report(data)
    // console.log(res);
    // console.log(res.result[].name);


    // 统计数据条数
    // console.log(res.result.length);
    // let count = document.querySelector('.count')
    let num = res.result.length
    // console.log(num);
    bigtitle.innerHTML += `
    <span class="count">共${num}条</span>
    `


    if (res.result.length > 0) {
        res.result.forEach(function (ele) {
            let nowday = new Date()
            // console.log(nowday);
            let select = ""
            let session = ""
            // console.log(ele.day_time);
            switch (ele.show_id) {
                case "1":
                    session = "9:00-12:00";
                    select = new Date(ele.day_time + " 12:00:00").getTime()
                    break;
                case "2":
                    session = "12:00-14:30";
                    select = new Date(ele.day_time + " 14:00:00").getTime()

                    break;
                case "3":
                    session = "14:30-17:30";
                    select = new Date(ele.day_time + " 17:00:00").getTime()
                    break;
            }

            let timeCom = nowday - select;
            if (timeCom < 0) {
                box.innerHTML += `
            <div class="record">
            <div class="conname">姓名:${ele.name}</div>
            <div class="condata">日期:${ele.day_time}</div>
            <div class="contime">场次:${session}</div>
            <div class="code">点击查看二维码</div>
            </div>
            `;
            }

        })
    } else {

        box.innerHTML = `
            <div class="none">
                    <div class="explain">没有记录</div>
                </div>
            `


    }


    //二维码弹出
    let bg = document.querySelector('.bg');
    let code = document.querySelectorAll('.code')
    // console.log(code);
    code.forEach(function (ele) {
        ele.addEventListener('click', function () {

            // bg.style.display = 'block'
            bg.style.transform = 'translateX(0)';
            codes()
        })

    })
    bg.addEventListener('click', function () {
        // bg.style.display = "none"
        bg.style.transform = 'translateX(-100%)';
    })
}


record()
async function codes() {
    // let url = "http://newshopapi.0melon0.cn/api/f_user/Qrcode";
    let data = {
        token: sessionStorage.getItem("token"),
        id: sessionStorage.getItem("id"),
    };
    // console.log(data);
    let res2 = await QCcode(data)
    // console.log(res2);

    let qccode = document.querySelector('.qccode');
    // console.log(res2);
    qccode.src = res2.data.data
}
